package com.acegear.horizon.domain.services;

import com.acegear.horizon.domain.models.jpa.UserInfo;
import com.acegear.horizon.domain.models.vo.FollowVO;
import com.acegear.horizon.domain.repository.jpa.UserFollowRepository;
import com.acegear.horizon.domain.repository.jpa.UserInfoRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wangsike on 2017/3/9.
 */
@Service
public class FollowService {
    @Autowired
    private UserFollowRepository userFollowRepository;

    @Autowired
    private UserInfoRepository userInfoRepository;

    public FollowVO getFollowVO(Long followeeId, Long followerId) {
        UserInfo userInfo = userInfoRepository.findByUserId(followeeId).get();
        Boolean isFollow = userFollowRepository.existsByFolloweeId(followeeId);
        return new FollowVO(userInfo.getUserId(), userInfo.getNickname(), userInfo.getAvatar(), isFollow);
    }

    public Boolean isFollow(Long followeeId) {
        return userFollowRepository.existsByFolloweeId(followeeId);
    }
}
